package com.zlj.accountant.app;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;

import com.zlj.accountant.Constant;
import com.zlj.accountant.R;
import com.zlj.accountant.core.TransactionHandlerManager;
import com.zlj.accountant.publish.task.InitSmsInAccountTask;

public class LoadingActivity extends Activity {
	
	
	@Override
	protected void onCreate(android.os.Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		checkExit();
		this.setContentView(R.layout.lyt_loading_page);
		new AsyncTask<Void, Void, Void>() {
			
			protected void onPostExecute(Void result) {
				Intent intent = new Intent();
				intent.setClass(LoadingActivity.this, MainActivity.class);
				startActivity(intent);
			};

			@Override
			protected Void doInBackground(Void... params) {
				TransactionHandlerManager handler = new TransactionHandlerManager(LoadingActivity.this);
				SharedPreferences sp = getSharedPreferences(Constant.SharedPre.Config,MODE_PRIVATE);
				boolean inited = sp.getBoolean(Constant.SharedPre.Config_SmsInited, false);
				if(!inited){
					handler.handle(new InitSmsInAccountTask());
				}				
				return null;
			}
		}.execute();
	}

	private void checkExit(){
	    Intent intent = getIntent();
	    boolean isExit = intent.getBooleanExtra("exit", false);
	    if(isExit){
	    	android.os.Process.killProcess(android.os.Process.myPid());
			finish();
	    }
    };
	
	
	
}
